class_name MotionControllerComponent
extends ControllerComponent

@export var speed:float
var angular_speed:float
var _target

func set_target_vel(delta:float):
	target_vel = Vector2(1,0).rotated(cur_entity.transform.get_rotation()) * speed
func get_target_angular_vel() -> float:
	return angular_speed
func flip():
	var vel:Vector2 = target_vel
	if (vel.x > 0.001 and cur_entity.scale.y < 0) or (vel.x < -0.001 and cur_entity.scale.y > 0):
		cur_entity.apply_scale(Vector2(1,-1))
func set_target(target):
	self._target = target

func _process(delta: float) -> void:
	super._process(delta)
	
func _physics_process(delta: float) -> void:
	super._physics_process(delta)
	if cur_entity:
		var entity = cur_entity as RigidEntity
		entity.set_linear_vel(get_target_vel())
